﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:controls="clr-namespace:RealWorldStocks.UI.Controls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" mc:Ignorable="d">


    <Style TargetType="controls:PriceChangeArrow">
    	<Setter Property="Height" Value="16"></Setter>
		<Setter Property="Width" Value="16"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:PriceChangeArrow">

                    <Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
                		<VisualStateManager.VisualStateGroups>
                			<VisualStateGroup x:Name="PriceStates">
                				<VisualStateGroup.Transitions>
                					<VisualTransition GeneratedDuration="0:0:0.5"/>
                				</VisualStateGroup.Transitions>
                				<VisualState x:Name="Negative">
                					<Storyboard>
                						<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="Arrow" d:IsOptimized="True"/>
                					</Storyboard>
                				</VisualState>
                				<VisualState x:Name="Positive">
                					<Storyboard>
                						<DoubleAnimation Duration="0" To="180" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="Arrow" d:IsOptimized="True"/>
                					</Storyboard>
                				</VisualState>
                			</VisualStateGroup>
                		</VisualStateManager.VisualStateGroups>   

                		<Path x:Name="Arrow" Stretch="Fill" Fill="{TemplateBinding Foreground}" Data="F1 M 7.00001,2L 13,2C 13.5523,2 14,2.44771 14,3L 13.9999,9L 16.9999,9C 17.5522,9 17.9999,9.44771 17.9999,10L 10.7072,17.2426C 10.3166,17.6332 9.68346,17.6332 9.29295,17.2426L 1.99992,10C 1.99992,9.44771 2.44764,9 2.99992,9L 5.99992,9L 6.00001,3C 6.00001,2.44771 6.44772,2 7.00001,2 Z " RenderTransformOrigin="0.5,0.5">
                			<Path.RenderTransform>
                				<CompositeTransform Rotation="90"/>
                			</Path.RenderTransform>
                		</Path>

                	</Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



    <ControlTemplate x:Key="PhoneDisabledTextBoxTemplate" TargetType="TextBox">
        <ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
    </ControlTemplate>

    <Style TargetType="controls:WatermarkedTextBox">
        <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        <Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/>
        <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/>
        <Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/>
        <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
        <Setter Property="Padding" Value="2"/>
        <Setter Property="WatermarkStyle">
            <Setter.Value>
                <Style TargetType="TextBlock">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="Margin" Value="3,0,0,0" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Setter Property="TextWrapping" Value="NoWrap" />
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="TextRemoverStyle">
            <Setter.Value>
                <Style TargetType="Button">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid Width="42" Height="42"
    							x:Name="LayoutRoot"
    							Background="{TemplateBinding Background}"
    							HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
    							Margin="{TemplateBinding Padding}"
    							VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualStateGroup.Transitions>
                                                <VisualTransition GeneratedDuration="0:0:0.3">
                                                    <VisualTransition.GeneratedEasingFunction>
                                                        <QuarticEase EasingMode="EaseInOut"/>
                                                    </VisualTransition.GeneratedEasingFunction>
                                                </VisualTransition>
                                            </VisualStateGroup.Transitions>
                                            <VisualState x:Name="Normal"/>
                                            <VisualState x:Name="MouseOver"/>
                                            <VisualState x:Name="Pressed" />
                                            <VisualState x:Name="Disabled"/>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                    <!--<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"/>-->

                                    <Path x:Name="path" Stretch="Fill"  HorizontalAlignment="Center" Margin="12.5,7.5,2.5,7.5" VerticalAlignment="Center" UseLayoutRounding="False" Data="M0.5,0.5 L8.5,8.5 M8.5000095,0.50000072 L0.50000954,8.500001" StrokeThickness="6">
                                        <Path.Stroke>
                                            <SolidColorBrush Color="#FF1F1F1F"/>
                                        </Path.Stroke>
                                    </Path>
                                    <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed"/>
                                    <Rectangle x:Name="DisabledVisualElement" Fill="#FFFFFFFF" RadiusX="3" RadiusY="3" IsHitTestVisible="false" Opacity="0"/>
                                    <Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" RadiusX="2" RadiusY="2" Margin="1" IsHitTestVisible="false" Opacity="0"/>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Background" Value="#FF494949"/>
                    <Setter Property="BorderBrush" Value="#FF494949"/>
                    <Setter Property="Foreground" Value="White"/>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:WatermarkedTextBox">
                    <Grid Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="EnabledBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DisabledOrReadonlyBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="ReadOnly">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="EnabledBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DisabledOrReadonlyBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="DisabledOrReadonlyBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="DisabledOrReadonlyBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DisabledOrReadonlyContent">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxReadOnlyBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="EnabledBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxEditBackgroundBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="EnabledBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxEditBorderBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="TextRemover">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxEditBackgroundBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="TextRemover">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>

                            <VisualStateGroup x:Name="WatermarkStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition From="WatermarkHidden" GeneratedDuration="00:00:00.4000000" To="WatermarkVisible"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="WatermarkVisible">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Watermark" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="WatermarkHidden">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Watermark" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border x:Name="EnabledBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}">
                            <ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
                        </Border>
                        <Border x:Name="DisabledOrReadonlyBorder" BorderBrush="{StaticResource PhoneDisabledBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" Margin="{StaticResource PhoneTouchTargetOverhang}" Visibility="Collapsed">
                            <TextBox x:Name="DisabledOrReadonlyContent" Background="Transparent" Foreground="{StaticResource PhoneDisabledBrush}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" IsReadOnly="True" SelectionForeground="{TemplateBinding SelectionForeground}" SelectionBackground="{TemplateBinding SelectionBackground}" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" Text="{TemplateBinding Text}" Template="{StaticResource PhoneDisabledTextBoxTemplate}"/>
                        </Border>

                        <TextBlock x:Name="Watermark"
                                           Style="{TemplateBinding WatermarkStyle}"
                                           Foreground="{TemplateBinding WatermarkForeground}"
                                           Text="{TemplateBinding WatermarkText}"
                                           IsHitTestVisible="False"
                                           Grid.ColumnSpan="2" Margin="22,0,0,2"/>

                        <Button x:Name="TextRemover" Margin="0,0,6,0" toolkit:TiltEffect.IsTiltEnabled="true"
		                            Style="{TemplateBinding TextRemoverStyle}" VerticalAlignment="Center" Content="Button"
		                            Grid.Column="1" IsTabStop="False" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Right"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <DataTemplate x:Key="WatchListItemTemplate">
        <HyperlinkButton Style="{StaticResource EmptyButtonStyle}" Width="430" Height="70" Margin="0,12">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="95.333"/>
                </Grid.ColumnDefinitions>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.529*"/>
                        <RowDefinition Height="0.471*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Symbol}" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Bottom"/>
                    <TextBlock Text="{Binding Company}" Grid.Row="1" Style="{StaticResource PhoneTextAccentStyle}" VerticalAlignment="Top"/>
                </Grid>
                <Grid HorizontalAlignment="Right" Width="136" d:LayoutOverrides="HorizontalMargin">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.595*"/>
                        <ColumnDefinition Width="0.405*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{Binding LastPrice}" Style="{StaticResource PhoneTextNormalStyle}" VerticalAlignment="Center" Margin="0" Foreground="{Binding DaysChange, Converter={StaticResource PriceChangeColorConverter}}" HorizontalAlignment="Right" FontSize="26.667" />
                    <controls:PriceChangeArrow Price="{Binding DaysChange}"  Grid.Column="1" Width="30" Height="30" Foreground="{Binding DaysChange, Converter={StaticResource PriceChangeColorConverter}}" VerticalAlignment="Center" Margin="0,2,0,0"/>
                </Grid>
                <Grid Grid.Column="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.5*"/>
                        <RowDefinition Height="0.5*" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding DaysChangeFormatted}" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" VerticalAlignment="Bottom"  Foreground="{Binding DaysChange, Converter={StaticResource PriceChangeColorConverter}}" HorizontalAlignment="Right"  />
                    <TextBlock Text="{Binding DaysChangePercentFormatted}" Grid.Row="1" Style="{StaticResource PhoneTextSubtleStyle}" VerticalAlignment="Top"  Foreground="{Binding DaysChange, Converter={StaticResource PriceChangeColorConverter}}" HorizontalAlignment="Right"/>
                </Grid>
            </Grid>
        </HyperlinkButton>
    </DataTemplate>

    <DataTemplate x:Key="NewsItemTemplate">
        <HyperlinkButton Style="{StaticResource EmptyButtonStyle}"  Width="430" d:DesignHeight="70" Margin="0,12">
            <i:Interaction.Behaviors>
                <controls:LaunchBrowserBehavior Url="{Binding Path=Url}" />
            </i:Interaction.Behaviors>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock TextWrapping="Wrap" Text="{Binding Title}" Style="{StaticResource PhoneTextLargeStyle}" Grid.Row="0" />
                <TextBlock TextWrapping="Wrap" Text="{Binding ArticleDate, Converter={StaticResource RelativeDateTimeConverter}}" Grid.Row="2" Style="{StaticResource PhoneTextAccentStyle}"/>
            </Grid>
        </HyperlinkButton>
    </DataTemplate>
</ResourceDictionary>